package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AnnualPlanWork;
import com.ruoyi.business.service.IAnnualPlanWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 年度计划工作Controller
 *
 * @author ruoyi
 * @date 2024-11-17
 */
@Api(tags = "年度计划工作管理",value = "年度计划工作管理", description = "年度计划工作管理，包括查询、新增、修改、删除等功能")
@RestController
@RequestMapping("/business/work")
public class AnnualPlanWorkController extends BaseController
{
    @Autowired
    private IAnnualPlanWorkService annualPlanWorkService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入年度计划工作数据", notes = "支持更新已有数据")
    public AjaxResult importData(
            @ApiParam(value = "上传的Excel文件", required = true) MultipartFile file,
            @ApiParam(value = "是否更新已有数据", required = true) boolean updateSupport) throws Exception
    {
        ExcelUtil<AnnualPlanWork> util = new ExcelUtil<AnnualPlanWork>(AnnualPlanWork.class);
        List<AnnualPlanWork> userList = util.importExcel("年度计划工作数据",file.getInputStream(),1);
        String operName = getUsername();
        String message = annualPlanWorkService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出年度计划工作数据模板", notes = "提供Excel模板用于导入")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<AnnualPlanWork> util = new ExcelUtil<AnnualPlanWork>(AnnualPlanWork.class);
        util.importTemplateExcel(response, "年度计划工作数据","年度计划工作数据");
    }

    /**
     * 查询年度计划工作列表
     */
    @PreAuthorize("@ss.hasPermi('business:work:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询年度计划工作列表", notes = "分页查询年度计划工作列表")
    public TableDataInfo list(AnnualPlanWork annualPlanWork)
    {
        startPage();
        List<AnnualPlanWork> list = annualPlanWorkService.selectAnnualPlanWorkList(annualPlanWork);
        return getDataTable(list);
    }

    /**
     * 导出年度计划工作列表
     */
    @PreAuthorize("@ss.hasPermi('business:work:export')")
    @Log(title = "年度计划工作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出年度计划工作列表", notes = "将查询到的年度计划工作数据导出为Excel文件")
    public void export(HttpServletResponse response, AnnualPlanWork annualPlanWork)
    {
        List<AnnualPlanWork> list = annualPlanWorkService.selectAnnualPlanWorkList(annualPlanWork);
        ExcelUtil<AnnualPlanWork> util = new ExcelUtil<AnnualPlanWork>(AnnualPlanWork.class);
        util.exportExcel(response, list, "年度计划工作数据");
    }

    /**
     * 获取年度计划工作详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:work:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取年度计划工作详细信息", notes = "根据ID查询年度计划工作详细信息")
    public AjaxResult getInfo(@ApiParam(value = "年度计划工作ID", required = true) @PathVariable("id") Long id)
    {
        return success(annualPlanWorkService.selectAnnualPlanWorkById(id));
    }

    /**
     * 新增年度计划工作
     */
    @PreAuthorize("@ss.hasPermi('business:work:add')")
    @Log(title = "年度计划工作", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增年度计划工作", notes = "添加新的年度计划工作记录")
    public AjaxResult add(@ApiParam(value = "年度计划工作对象", required = true) @RequestBody AnnualPlanWork annualPlanWork)
    {
        return toAjax(annualPlanWorkService.insertAnnualPlanWork(annualPlanWork));
    }

    /**
     * 修改年度计划工作
     */
    @PreAuthorize("@ss.hasPermi('business:work:edit')")
    @Log(title = "年度计划工作", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改年度计划工作", notes = "更新现有的年度计划工作记录")
    public AjaxResult edit(@ApiParam(value = "年度计划工作对象", required = true) @RequestBody AnnualPlanWork annualPlanWork)
    {
        return toAjax(annualPlanWorkService.updateAnnualPlanWork(annualPlanWork));
    }

    /**
     * 删除年度计划工作
     */
    @PreAuthorize("@ss.hasPermi('business:work:remove')")
    @Log(title = "年度计划工作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除年度计划工作", notes = "根据ID删除年度计划工作记录")
    public AjaxResult remove(@ApiParam(value = "年度计划工作ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(annualPlanWorkService.deleteAnnualPlanWorkByIds(ids));
    }
}
